package com.medishare.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

import com.medishare.R;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import android.util.Log;

public class Utils {
	public static boolean DEBUG = true;
	public static String TAG = Utils.class.getSimpleName();
	public static final String  UUID = "uuid";
	public static final String MEMBER_ID = "member_id";
	public static final String TYPE = "type";
	public static final String CARDID = "cardid";
	public static String getDeviceUUID(Context context){

		  final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);   

		  final String tmDevice;   

		  tmDevice = tm.getDeviceId();  

		  return tmDevice;

		 }
	public static String getBaseUrl(){
		return "http://4.medishare.sinaapp.com/index.php/";
	}
	
	public static String convertTime(String time) {
		Date date;
		if(time != null){
	    long timeStamp = Long.parseLong(time) * 1000;
	    date = new Date(timeStamp);       
		}else{
		date = new Date();
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(date);
	}
	
	public static boolean isNetworkAvailable(Context context) { 
		ConnectivityManager connectivity = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); 
		if (connectivity == null) { 
		Log.i("NetWorkState", "Unavailabel"); 
		return false; 
		} else { 
		NetworkInfo[] info = connectivity.getAllNetworkInfo(); 
		if (info != null) { 
		for (int i = 0; i < info.length; i++) { 
		if (info[i].getState() == NetworkInfo.State.CONNECTED) { 
		Log.i("NetWorkState", "Availabel"); 
		return true; 
		} 
		} 
		} 
		} 
		return false; 
		} 
}
